const express = require("express");
const app = express();

app.use((request, response, next) => {
  console.log("有人请求的服务器");
  next();
});

app.post("/login", (request, response) => {
  const token = "111111111";
  response.send(token);
});

app.get("/getInfo", (request, response) => {
  const info = {
    roles: ["admin"],
    permissions: ["*:*:*"],
    user: {
      userId: 1,
      userName: "admin",
    },
  };
  response.send(info);
});

app.get("/getRouters", (request, response) => {
  const menu = [
    {
      name: "System",
      path: "/system",
      hidden: false,
      redirect: "noRedirect",
      component: "Layout",
      alwaysShow: true,
      meta: {
        title: "系统管理",
        icon: "system",
        noCache: false,
        link: null,
      },
      children: [
        {
          name: "Dict",
          path: "dict",
          component: "system/dict/index",
          meta: {
            title: "字典管理",
            icon: "dict",
            noCache: false,
            link: null,
          },
        },
        {
          name: "Config",
          path: "config",
          component: "system/config/index",
          meta: {
            title: "参数设置",
            icon: "edit",
            noCache: false,
            link: null,
          },
        },
        {
          name: "Menu",
          path: "menu",
          component: "system/menu/index",
          meta: {
            title: "菜单管理",
            icon: "tree-table",
            noCache: false,
            link: null,
          },
        },
        {
          name: "Role",
          path: "role",
          component: "system/role/index",
          meta: {
            title: "角色管理",
            icon: "peoples",
            noCache: false,
            link: null,
          },
        },
        {
          name: "User",
          path: "user",
          hidden: false,
          component: "system/user/index",
          meta: {
            title: "用户管理",
            icon: "",
            noCache: false,
            link: null,
          },
        },
      ],
    },
  ];
  response.send(menu);
});

app.listen(5000, (err) => {
  if (!err)
    console.log("服务器启动成功了，请求信息地址：http://localhost:5000");
});
